package main

import (
	"flag"
	"fmt"
	"log"
	"smsrpc/constant"
	"smsrpc/sms"

	"golang.org/x/net/context"
	"google.golang.org/grpc"
)

var (
	address = flag.String("addr", "127.0.0.1", "rpc server address")
	port    = flag.String("port", "1142", "rpc server port")
)

func main() {
	flag.Parse()

	serverAddress := fmt.Sprintf("%s:%s", *address, *port)
	conn, err := grpc.Dial(serverAddress, grpc.WithInsecure())
	if err != nil {
		log.Fatalf("did not connect rpc server %s error %v", serverAddress, err)
	}
	defer conn.Close()

	c := sms.NewSmsClient(conn)
	if err := testGetClientInfo(c); err != nil {
		log.Println(err)
	}
}

func testGetClientInfo(c sms.SmsClient) error {
	resp, err := c.GetSmsClientInfo(context.Background(), &sms.GetSmsClientRequest{
		ChannelId: constant.DefaultChannelId,
	})
	if err != nil {
		return nil
	}
	log.Println(*resp)

	return nil
}
